<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="root">
        
    </div>

    <script src="https://unpkg.com/react@18/umd/react.development.js" crossorigin></script>
    <script src="https://unpkg.com/react-dom@18/umd/react-dom.development.js" crossorigin></script>
    <script src="https://unpkg.com/babel-standalone@6.15.0/babel.min.js"></script>

   
    <script type="text/babel">
        class InputElement extends React.Component{
            constructor(props){
                super(props);
            }
            componentWillReceiveProps(newProps){
                console.log("InputElement componentWillReceiveProps",newProps);
            }
            render(){
                console.log("InputElement render")
                return <div>
                        <input type="text" value={this.props.value}/>
                    </div>
            }
        }
        class DivElement extends React.Component{
            state = {
                value:"hello",
                checked:false
            }
            myInput = React.createRef();
            constructor(props){
                super(props);
            }
            handleClick(){
                console.log("click",this.myInput.current.value);
                
            }
            handleChange = (e) => {
                this.setState({
                    value:e.target.value
                });
            }
            componentWillMount(){
                console.log("componentWillMount");
            }
            componentDidMount(){
                console.log("componentDidMount");
            }
            componentWillReceiveProps(newProps){
                console.log("componentWillReceiveProps",newProps);
            }
            shouldComponentUpdate(newProps,newState){
                console.log("shouldComponentUpdate",newProps,newState);
                return true;
            }
            componentWillUpdate(){
                console.log("componentWillUpdate");
            }
            componentDidUpdate(){
                console.log("componentDidUpdate");
            }
            render(){
                console.log("render");
                // 钩子
                return <div>
                        <input type="button" value="OK" onClick={() => this.handleClick()} />
                        <input ref={this.myInput} type="text" value={this.state.value} onChange={this.handleChange} />
                        <input type="checkbox" 
                            checked={this.state.checked} 
                            onChange={(e) => this.setState({checked:e.target.checked})} />
                        <InputElement value={this.state.value}></InputElement>
                    </div>
            }
        }
        const root = ReactDOM.createRoot(document.getElementById("root"));
        root.render(<DivElement cnt="0"></DivElement>);
    </script>
</body>
</html>